#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>

#define NUM_THREADS     10
/*
 * Example copied from wikipedia
 */
void *TaskCode(void *argument) {
	int tid;
	int i;

	tid = *((int *) argument);
	for (i = 0; i < 1000; i++) {
		printf("Hello World! It's me, thread %d, %d!\n", tid, i);
	}

	/* optionally: insert more useful stuff here */

	return NULL;
}

int main(void) {
	pthread_t threads[NUM_THREADS];
	int thread_args[NUM_THREADS];
	int rc, i;

	/* create all threads */
	for (i = 0; i < NUM_THREADS; ++i) {
		thread_args[i] = i;
		printf("In main: creating thread %d\n", i);
		rc = pthread_create(&threads[i], NULL, TaskCode,
				(void *) &thread_args[i]);
		assert(0 == rc);
	}

	/* wait for all threads to complete */
	for (i = 0; i < NUM_THREADS; ++i) {
		rc = pthread_join(threads[i], NULL);
		assert(0 == rc);
	}

	exit(EXIT_SUCCESS);
}

